// pages/Vip/deal/deal.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		data: '',
		sta:0,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(e) {
		wx.getStorage({
			key:'user',
			success: (e) => {
				console.log(e)
			}
		})
		wx.getStorage({
			key:'uid',
			success: (e) => {
				this.setData({
					uid:e.data.uid
				})
			}
		})
		console.log(e)
		this.setData({
			data: e
		})
	},
	fafa(e){
		console.log(e)
		this.setData({
			sta:e.detail.value
		})
	},
	deal() {
		if(this.data.sta==0){
			wx.getStorage({
				key: 'user',
				success: (res) => {
					console.log(res)
					wx.request({
						url: getApp().globalData.map+'/tools/xiadan.ashx?openid=' + res.data.openId + '&orderNo=' + this.data.data.orderCode +
							'&price=' + this.data.data.totalprice,
						success: (e) => {
							console.log(e)
							wx.requestPayment({
								'timeStamp': e.data.timeStamp,
								'nonceStr': e.data.nonceStr,
								'package': e.data.package,
								'signType': e.data.signType,
								'paySign': e.data.paySign,
								'success': function(res) {
									wx.redirectTo({
										url:'../ues/use'
									})
								},
								'fail': function(res) {
									console.log(res)
								},
							})
						}
					})
				}
			})
		}else{
			wx.request({
				url:getApp().globalData.http2+"action=orderZF&ID="+this.data.data.id+'&payType=3',
				success: (e) => {
					console.log(e)
					if(e.data.code==1){
						wx.switchTab({
							url:'../../set/set'
						})
					}else{
						wx.showToast({
							title:e.data.msg,
							icon:'none'
						})
					}
				}
			})
		}
	},
})
